package service

import (
	"io/ioutil"
)

type FileDir struct {
}

type FilesList struct {
	Data []*Files `json:"data"`
}

type Files struct {
	Name  string `json:"name"`
	IsDir bool   `json:"isDir"`
	//Path  string `json:"path"`
}

func (fd FileDir) ReadFileList(dirPath string) (*FilesList, error) {
	var fl = &FilesList{}

	//获取文件或目录相关信息
	fileInfoList, err := ioutil.ReadDir(dirPath)
	if err != nil {
		return fl, err
	}

	for _, file := range fileInfoList {
		fl.Data = append(fl.Data, &Files{file.Name(), file.IsDir()})
	}

	return fl, nil
}
